﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace PlantsVsZombies
{
    public class Map : VisibleGameEntity
    {
        public static float WidthCell = 81f;
        public static float HeightCell = 98f;
        public static float CoordinateX = 34f;
        public static float CorrdinateY = 86f;
        public static float WidthMap = 770f;
        public static float HeightMap = 577f;
        public static int Rows = 5;
        public static int Cols = 9;

       
       

        public static Vector2 StandardizedPos(Vector2 position)
        {
            int row = 0;
            int column = 0;
            position.X -= CoordinateX;
            position.Y -= CorrdinateY;

            Pos2Cell(position,ref row, ref column);

            return new Vector2( (column-1) * WidthCell +  CoordinateX , (row-1) * HeightCell +  CorrdinateY + HeightCell/4);
        }

        /*
        * chuyen tu do do bat ki
        * sang vi tri row, column tuong ung
        */

        public static void Pos2Cell(Vector2 position, ref int row, ref int column)
        {
            column = (int)(position.X / WidthCell);
            if (position.X - (WidthCell * column) > 0.5 )
                column++;

            row = (int)(position.Y / HeightCell);
            if (position.Y - (HeightCell * row) > 0.5 )
                row++;
        }
        /*
         * kiem tra xem vi tri click 
         * co nam trong ban do hay k
         */

        public static bool IsAreaRegular(Vector2 position)
        {
            if (position.X >= CoordinateX && position.X <= WidthMap)
                if (position.Y >= CorrdinateY && position.Y <= HeightMap)
                    return true;
            return false;
        }

       
        
        public Map(ContentManager contentManager, String textMap,Vector2 size, Vector2 pos )
        {
            Texture2D[] texture2 = new Texture2D[1];
            texture2[0] = contentManager.Load<Texture2D>(textMap);
            Sprite tempSprite = new Sprite(texture2,pos,size);         
            NSprites = 1;
            Sprites = new List<Sprite>();
            Sprites.Add(tempSprite);
        }
    }
}
